package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.constant.DeliveryOrderTypeStatusEnum;
import com.ssy.lingxi.order.model.vo.basic.request.*;
import com.ssy.lingxi.order.model.vo.basic.response.DeliveryOrderDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.DeliveryOrderProductQueryVO;
import com.ssy.lingxi.order.model.vo.basic.response.DeliveryOrderQueryVO;
import com.ssy.lingxi.order.model.vo.basic.response.ReceiveOrderQueryVO;
import com.ssy.lingxi.order.service.web.IDeliveryOrderService;
import com.ssy.lingxi.order.service.web.IReceiveOrderService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 订单能力 - 送货单
 * @author ds
 * @version 2.0.0
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/order/delivery/order")
public class DeliveryOrderController {
    @Resource
    private IDeliveryOrderService deliveryOrderService;
    @Resource
    private IReceiveOrderService receiveOrderService;
    /**
     * “送货单” - 送货单管理（SRM）-分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/srm/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryOrderQueryVO>> pageBySRM(@RequestHeader HttpHeaders headers, @Valid DeliveryOrderPageVO request) {
        return deliveryOrderService.pageBySRM(headers, request);
    }


    /**
     * 新增送货单（SRM）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/srm/create", method = RequestMethod.POST)
    public Wrapper<Void> createBySRM(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryOrderCreateVO request) {
        return deliveryOrderService.createDeliveryOrder(headers, request, DeliveryOrderTypeStatusEnum.SRM.getCode());
    }

    /**
     * “送货单” - 送货单管理（B2B）-分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/b2b/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryOrderQueryVO>> pageByB2B(@RequestHeader HttpHeaders headers, @Valid DeliveryOrderPageVO request) {
        return deliveryOrderService.pageByB2B(headers, request);
    }

    /**
     * 新增送货单（B2B）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/b2b/create", method = RequestMethod.POST)
    public Wrapper<Void> createByB2B(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryOrderCreateVO request) {
        return deliveryOrderService.createDeliveryOrder(headers, request, DeliveryOrderTypeStatusEnum.B2B.getCode());
    }

    /**
     * “送货单” - 详情
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<DeliveryOrderDetailVO> detail(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return deliveryOrderService.detail(headers, request);
    }

    /**
     * “送货单” - 详情 - 物料分页列表
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail/product/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryOrderProductQueryVO>> pageProducts(@RequestHeader HttpHeaders headers, @Valid DeliveryOrderProductPageVO request) {
        return deliveryOrderService.pageProducts(headers, request);
    }

    /**
     * 修改送货单
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryOrderUpdateVO request) {
        return deliveryOrderService.update(headers, request);
    }

    /**
     * 作废送货单
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/invalid", method = RequestMethod.POST)
    public Wrapper<Void> invalid(@RequestHeader HttpHeaders headers, @RequestBody @Valid InvalidVO request) {
        //暂废弃，涉及订单流程变更return deliveryOrderService.invalid(headers, request);
        return Wrapper.success();
    }

    /**
     * “送货单” - 收货单管理 -分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/receive/page", method = RequestMethod.GET)
    public Wrapper<PageData<ReceiveOrderQueryVO>> pageByVendor(@RequestHeader HttpHeaders headers, @Valid ReceiveOrderPageVO request) {
        return receiveOrderService.pageByVendor(headers, request);
    }
}
